package
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.text.Font;
	import flash.text.TextField;

	public class MyGraphics
	{
		protected var backBuffer:BitmapData;
		public function MyGraphics(width:int, height:int)
		{
			backBuffer = new BitmapData(width, height, false);
		}
		public function Width():int
		{
			return backBuffer.width;
		}
		public function Height():int
		{
			return backBuffer.height;
		}
		public function FillRect(x:Number, y:Number, width:Number, height:Number, color:uint):void
		{
			backBuffer.fillRect(new Rectangle(x,y,width,height), color);
		}
		public function Clear(color:uint):void
		{
			backBuffer.fillRect(new Rectangle(0,0,backBuffer.width,backBuffer.height), color);
		}
		public function DrawCircle(x:Number, y:Number, radius:Number, color:uint):void
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(color);
			shape.graphics.drawCircle(x,y,radius);
			shape.graphics.endFill();
			backBuffer.draw(shape);
		}
		public function DrawBitmapData(x:Number, y:Number, bm:BitmapData):void
		{
			var matrix:Matrix = new Matrix();
			matrix.translate(x, y);
			backBuffer.draw(bm,matrix);
		}
		public function DrawMovieClip(x:Number, y:Number, mv:MovieClip):void
		{
			var matrix:Matrix = new Matrix();
			matrix.translate(x, y);
			backBuffer.draw(mv,matrix);
		}
		public function Flip(g:Graphics):void
		{
			g.clear();
			g.beginBitmapFill(backBuffer);
			g.drawRect(0,0,backBuffer.width,backBuffer.height);
			g.endFill();
		}
		public function DrawString(s:String, x:Number, y:Number, color:uint):void
		{
			var tx:TextField = new TextField();
			tx.text = s;
			tx.textColor = color;
			var matrix:Matrix = new Matrix();
			matrix.translate(x, y);
			backBuffer.draw(tx, matrix);
		}
		public function SetFont(name:String, size:uint, color:uint):void
		{
			
		}
	}
}